import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'

interface USER{
  phone:string | number,
  password:string|number
}
export const useCounterStore = defineStore('counter', () => {
  // 数字变化
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2);
 
  function increment() {
    count.value++;
    
  }


  const users=ref<USER>({phone:"",password:""});
  
  //身份验证
  let token={
    setToken:(obj:object)=>{
        localStorage.setItem('users',JSON.stringify(obj));
        users.value=JSON.parse(localStorage.getItem('users') as string | any)
    },
    getToken:()=>{
     return  users.value= JSON.parse(localStorage.getItem('users') as string |any)
    },
    removeToken:()=>{
      localStorage.removeItem("users");
      users.value={phone:"",password:""};
    }
  }
  

  return { count, doubleCount, increment,token,users }
})
